#!/usr/bin/python

###
###  The purpose of this program is to take the string
###  provided as an argument and produce a has from it.
###  That hash is turn will be used by the jterm program
###  for window color selection
### 

import warnings
warnings.filterwarnings("ignore")

import md5
import sys

debug    = False
maxTerms = 41
divisor  = 2

hostname=sys.argv[1]
if debug:
   print "hostname : " + str(hostname)

m = md5.new(hostname)
hosthash = m.hexdigest()[0:3]
if debug:
  print "  "
  print "hash1 : " + str(hosthash) + " " ,

hosthash = hosthash.encode('hex')
if debug:
  print "hash2 : " + str(hosthash) + " ",

result    = int(hosthash) / maxTerms
remainder = int(hosthash) % maxTerms 
if remainder == 0 :
  remainder = remainder + maxTerms

if debug:
  print "rslt : " + str(result) + " ",
  print "rmdr : " + str(remainder) + " ",

finalHash = result % remainder
if finalHash == 0 :
  finalHash = finalHash + maxTerms

print str(finalHash).zfill(2)

